All sample codes from this lesson: ******************************************************** WHILE introduction: void setup() { // put your setup code here, to run once: pinMode (2,INPUT_PULLUP); Serial.begin(9600); while (digitalRead(2)==HIGH) { Serial.println("Here I am, just a loopin!"); } Serial.println("I have now escaped out of the while loop"); } void loop() { // put your main code here, to run repeatedly: } ******************************************************** FOR loop, example 1: void setup() { // put your setup code here, to run once: pinMode (2,INPUT_PULLUP); pinMode (3,OUTPUT); } void loop() { // put your main code here, to run repeatedly: for (int bright=0; bright <256; bright++){ //this first loop increases the brightness of the LED until it hits maximum brightness analogWrite (3,bright); delay(10); } for (int bright=255; bright >=0; bright--){ //this first loop decreases the brightness of the LED until it hits minimum brightness analogWrite (3,bright); delay(10); } } ******************************************************** FOR loop, example 2: void setup() { // put your setup code here, to run once: pinMode (2,INPUT_PULLUP); pinMode (3,OUTPUT); } void loop() { // put your main code here, to run repeatedly: for (int bright=0; bright <256; bright=bright+51){ //this first loop increases the brightness of the LED until it hits maximum brightness analogWrite (3,bright); delay(500); } for (int bright=255; bright >=0; bright=bright-51){ //this first loop decreases the brightness of the LED until it hits minimum brightness analogWrite (3,bright); delay(500); } } ******************************************************** FOR loop, example 3: void setup() { // put your setup code here, to run once: pinMode (2,INPUT_PULLUP); pinMode (3,OUTPUT); } void loop() { // put your main code here, to run repeatedly: for (int bright=0; bright <256; bright++){ //this first loop increases the brightness of the LED until it hits maximum brightness analogWrite (3,bright); delay(500); bright=bright+51; } for (int bright=255; bright >=0; bright--){ //this first loop decreases the brightness of the LED until it hits minimum brightness analogWrite (3,bright); delay(500); bright=bright-51; } } ******************************************************** FOR loop, example 4: void setup() { // put your setup code here, to run once: pinMode (2,INPUT_PULLUP); pinMode (3,OUTPUT); } void loop() { // put your main code here, to run repeatedly: for (int bright=0; bright <256; bright++){ //this first loop increases the brightness of the LED until it hits maximum brightness analogWrite (3,bright); delay(500); if (digitalRead(2)==LOW) { bright=bright+51; } } for (int bright=255; bright >=0; bright--){ //this first loop decreases the brightness of the LED until it hits minimum brightness analogWrite (3,bright); delay(500); if (digitalRead(2)==LOW) { bright=bright-51; } } }